#!/bin/bash

echo "* [starting](README.md)" > SUMMARY.md
echo "* [introduction](INTRODUCTION.md)" >> SUMMARY.md
for dir in `ls`; do
    if [ -d $dir -a $dir != _book ]; then
        echo "* $dir" >> SUMMARY.md
        for target in `ls $dir`; do
            if [ -d "$dir/$target" ]; then
                echo "    * [$target]($dir/$target/index.md)" >> SUMMARY.md
            elif [ `expr match $target ".*\.md$"` -gt 0 ]; then
                echo "    * [`echo $target|awk -F .md '{print $1}'`]($dir/$target)" >> SUMMARY.md
            fi
        done
    fi
done